/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entidade;

import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.MediaType;
import org.apache.catalina.util.Base64;

/**
 * REST Web Service
 *
 * @author Jesse
 */
@Path("Calculadora")
public class CalculadoraResource {

    @Context
    private UriInfo context;

    /**
     * Creates a new instance of CalculadoraResource
     */
    public CalculadoraResource() {
    }

    /**
     * Retrieves representation of an instance of entidade.CalculadoraResource
     * @return an instance of java.lang.String
     */
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/calcular")
    
    public String calcular(@QueryParam("operacao") String operacao, @QueryParam("nun1") int nun1, @QueryParam("nun2") int nun2) {
        try{
        if(operacao.equals("soma")){
            return "o resultado da operacao e"+ (nun1 + nun2); 
        }else if(operacao.equals("subitracao")){
            return "o resultado da operacao e"+ (nun1 - nun2);
        }else if(operacao.equals("multiplicao")){
           return "o resultado da operacao e"+ (nun1 * nun2);
        }else if(operacao.equals("dividivisao")){
            try{
            return "o resultado da operacao e"+ (nun1 / nun2);
            }catch(Exception e){
                return "Aconteceu um erro";
            }
        }
        }catch(Exception e){
           return "Aconteceu um erro"; 
        }
        return "O resultado da operacao e ";
    }

    /**
     * PUT method for updating or creating an instance of CalculadoraResource
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("text/plain")
    public void putText(String content) {
    }
}
